package modular.demo1;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class FlowReduceMapper extends Reducer<Text, FlowBean, Text, FlowBean> {

    /**
     * key 是某个手机号
     *
     * @author yuelinbo
     * @date 2018/12/21 15:14
     **/
    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Context context) throws IOException, InterruptedException {

        int upSum = 0;
        int downSum = 0;

        for (FlowBean bean : values) {

            upSum += bean.getUpFlow();
            downSum += bean.getDownFlow();
        }

        context.write(key,new FlowBean(upSum,downSum,upSum+downSum,key.toString()));


    }
}
